import { useUserStore,useWebConfigStore,useRefs } from "@/stores";
import {useStorage} from './storage';
export const useGameCustom=(game:string)=>{
	const storeage=useStorage();
	const webConfigStore = useWebConfigStore();
	const { WEBCONFIG } = useRefs(webConfigStore);
	const userStore = useUserStore();
	const { USERINFO } = useRefs(userStore);
	const get=()=>{
		switch (WEBCONFIG.value?.game_custom_role) {
			case 'login':
				if (!userStore.hasLogin()) {
					return Promise.reject('请先登录');
				}
				break;
			case 'vip':
				if(!userStore.hasLogin()){
					return Promise.reject('请先登录');
				}else if(!USERINFO.value?.vip_state){
					return Promise.reject('请先开通'+WEBCONFIG.value?.vip_member_name);
				}
				break;
		}
		return new Promise((resolve,reject)=>{
			const data=storeage.get('GAME_CUSTOM.' + game);
			if(data){
				resolve(data);
			}else{
				reject('没有数据');
			}
		})
	}
	const set=(data:any)=>{
		switch (WEBCONFIG.value?.game_custom_role) {
			case 'login':
				if (!userStore.hasLogin()) {
					return Promise.reject('请先登录');
				}
				break;
			case 'vip':
				if(!userStore.hasLogin()){
					return Promise.reject('请先登录');
				}else if(!USERINFO.value?.vip_state){
					return Promise.reject('请先开通'+WEBCONFIG.value?.vip_member_name);
				}
				break;
		}
		return storeage.set('GAME_CUSTOM.' + game, data);
	}
	return {
		get,
		set
	};
}